<%@ page import="java.awt.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>用户中心</title>
    <script src="<c:url value="/resources/core/js/jquery-3.1.1.min.js" />"></script>
    <script src="<c:url value="/resources/core/js/bootstrap.min.js" />"></script>

    <link href="${bootstrapCss}" rel="stylesheet"/>

    <%
        String mainPage = (String) request.getAttribute("mainPage");
            if (mainPage == null || mainPage.equals("")) {
                mainPage = "newFile.jsp";
            }
    %>
</head>
<body class="container">
<table width="96%" height="92%" align="center" cellspacing="20px;"
       cellpadding="20px;" style="margin-top: 45px;">
    <tr>
        <td style="background-color: #F8F8F8;">
            <jsp:include
                    page="head.jsp"></jsp:include>
        </td>
    </tr>
    <tr>
        <td height="450px" valign="top">
            <jsp:include
                    page="<%=mainPage%>"></jsp:include>
        </td>
    </tr>
    <tr>
        <td>
            <jsp:include page="Page.jsp"></jsp:include>
        </td>
    </tr>
    <tr>
        <td>
            <jsp:include page="foot.jsp"></jsp:include>
        </td>
    </tr>
</table>
</body>


<script type="text/javascript">
    //复选框事件
    //全选、取消全选的事件
    $('.checkItem').bind('click', setSelectAll)

    function selectAll() {
        var arr = $(".checkItem")
        if ($('#SelectAll').is(':checked')) {
            forEach.call(arr, function (item) {
                item.checked = true
            })
        } else {
            forEach.call(arr, function (item) {
                item.checked = false
            })
        }

    }

    function forEach(fn) {
        for (var i = 0; i < this.length; i++) {
            fn(this[i])
        }
    }

    //子复选框的事件
    function setSelectAll() {
        var chsub = $("input[class='checkItem'][type='checkbox']").length; //获取subcheck的个数
        var checkedsub = $("input[class='checkItem'][type='checkbox']:checked").length; //获取选中的subcheck的个数
        //当没有选中某个子复选框时，SelectAll取消选中
        //alert(chsub  +  "   =====  "+ checkedsub);
        if (!$(this).is(':checked')) {
            $("#SelectAll")[0].checked = false
        }
        if (checkedsub == chsub) {
            $("#SelectAll")[0].checked = true
        }
    }

    //删除文件
    function delFile() {
        var ids = '';
        $(".checkItem").each(function (index, item) {
            console.info(item)
            var text = ''
            if ($(item).is(':checked')) {
                text = $(item).parent().parent().find('td').eq(4).text();
                ids += text + ',';
            }
        });
        console.info(ids)
        if ("" == ids) {
            alert("请选择要删除的文件！！！");
            return;
        }
        //把得到的全部id值传到后台
        $.ajax({
            url: '/disktalk/file/delete',
            method: 'post',
            data: {
                ids: ids
            },
            success: function (result) {
                var info = eval('(' + result + ')');
                alert(info.result);
                window.location.reload();
            }
        });
    }

    //文件下载
    function download() {
        var ids = '';
        $(".checkItem").each(function (index, item) {
            console.info(item)
            var text = ''
            if ($(item).is(':checked')) {
                text = $(item).parent().parent().find('td').eq(4).text();
                ids += text + ',';
            }
        });

        console.info(ids)
        //把得到的全部id值传到后台
        $.ajax({
            url: '/disktalk/file/download',
            method: 'post',
            data: {
                ids: ids
            },
            success: function (result) {
                var info = eval('(' + result + ')');
                alert(info.result);
            }
        });
    }

    //分享文件
    function shareFile() {
        var ids = '';
        $(".checkItem").each(function (index, item) {
            console.info(item)
            var text = ''
            if ($(item).is(':checked')) {
                text = $(item).parent().parent().find('td').eq(4).text();
                ids += text + ',';
            }
        });
        //console.info(ids)
        if ("" == ids) {
            alert("请选择要分享的文件！！！");
            return;
        }
        //把得到的全部id值传到后台
        $.ajax({
            url: '/disktalk/file/share',
            method: 'post',
            data: {
                ids: ids
            },
            success: function (result) {
                var info = eval('(' + result + ')');
                alert(info.result);
                window.location.reload();
            }
        });
    }

    function fileSearch() {
        var content = $("td:input[name='content']").val();
        var select = $("[name='searchValue']").val();
        var userName = $("td:input[name='userName']").val();
        alert(conten + "  111 " + select + " 222 " + userName);
        $.ajax({
            url: '/disktalk/file/search',
            method: 'post',
            data: {
                select: select,
                content: content,
                userName: userName
            },
            success: function (result) {
                var info = eval('(' + result + ')');
                if (!info.result) {
                    alert("提取的密码有误！！！");
                } else {
                    window.location.href = '/disktalk/file/download?ids=' + uuid;
                    $("button[name='close']").click();
                }
            }
        });
    }
</script>

</html>